//
//  RTJInvestmentRootController.m
//  RuiTaiJinProject
//
//  Created by jayson on 2018/12/11.
//  Copyright © 2018年 leewei. All rights reserved.
//

#import "RTJInvestmentRootController.h"
#import "RTJNoInvestmentController.h"
#import "RTJHasInvestedController.h"

@interface RTJInvestmentRootController ()

@property (weak, nonatomic) IBOutlet UIButton *ongoingBtn;
@property (weak, nonatomic) IBOutlet UIButton *endingBtn;
@property (strong, nonatomic) IBOutlet MXPagerView *pageView;
@property (weak, nonatomic) IBOutlet UIImageView *bottomImg;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewTop;

@property(nonatomic,strong) RTJHasInvestedController *ongoingVC;
@property(nonatomic,strong) RTJNoInvestmentController *endingVC;

@end

@implementation RTJInvestmentRootController

-(void)viewDidAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = YES;
    
}

-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.viewTop.constant = screenH > 811 ? 24 : 0; self.navigationController.navigationBarHidden = YES;
    
    [self initViewControllers];
    
    //    [self changeBtnStatu:_isHongbao==YES ? 0 :1];
    //    [self.pageView showPageAtIndex:_isHongbao==YES ? 0 :1 animated:YES];
    
}

-(void)initViewControllers{
    
    _ongoingVC=[[RTJHasInvestedController alloc]init];
    [self addChildViewController:_ongoingVC];
    [_ongoingVC didMoveToParentViewController:self];
    
    _endingVC=[[RTJNoInvestmentController alloc]init];
    [self addChildViewController:_endingVC];
    [_endingVC didMoveToParentViewController:self];
    
}

- (IBAction)buttonItemPressed:(UIButton *)sender {
    
    if (sender.tag == 10) {
        
        [self changeBtnStatu:0];
        
        [self.pageView showPageAtIndex:0 animated:YES];
        
        
    }else{
        
        [self changeBtnStatu:1];
        
        [self.pageView showPageAtIndex:1 animated:YES];
        
    }
}

#pragma mark - MXPagerViewDataSource

- (NSInteger)numberOfPagesInPagerView:(MXPagerView *)pagerView
{
    return 2;
}

- (nullable __kindof UIView *) pagerView:(MXPagerView *)pagerView viewForPageAtIndex:(NSInteger)index
{
    switch (index) {
        case 0:
            
            return _ongoingVC.view;
            
            break;
            
        case 1:
            
            return _endingVC.view;
            
            break;
    }
    
    return nil;
}


#pragma mark - MXPagerViewDelegate

- (void)pagerView:(MXPagerView *)pagerView didMoveToPageAtIndex:(NSInteger)index
{
    if (index==0) {
        
        [UIView animateWithDuration:0.5 animations:^{
            
            [self changeBtnStatu:index];
            
        } completion:^(BOOL finished) {
            
        }];
        
    }
    else if (index==1) {
        [UIView animateWithDuration:0.5 animations:^{
            
            [self changeBtnStatu:index];
            
        } completion:^(BOOL finished) {
        }];
    }
}

-(void)changeBtnStatu:(NSUInteger )index{
    
    if (index==0) {
        
        [_ongoingBtn setTitleColor:[UIColor colorForHex:@"#333333"] forState:UIControlStateNormal];
        
        _bottomImg.centerX = _ongoingBtn.centerX;
        
        [_endingBtn setTitleColor:[UIColor colorForHex:@"#999999"] forState:UIControlStateNormal];
        
        
    }else{
        
        [_endingBtn setTitleColor:[UIColor colorForHex:@"#333333"] forState:UIControlStateNormal];
        
        _bottomImg.centerX = _endingBtn.centerX;
        
        [_ongoingBtn setTitleColor:[UIColor colorForHex:@"#999999"] forState:UIControlStateNormal];
        
    }
    
}

- (IBAction)back:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


@end
